package main

import "fmt"

func main()  {
	arr := []int{1,8,6,2,5,4,8,3,7}
	fmt.Println(arr)
	fmt.Println(calMax(arr))
}

func calMax(arr []int) int  {
	if len(arr) <= 1 {
		return 0
	}
	i :=0
	j := len(arr) -1
	max := 0
	for i < j {
		w := j - i
		h := 0
		if arr[i] < arr[j] {
			h = arr[i]
			i++
		}else {
			h = arr[j]
			j--
		}
		area := w * h
		if max < area {
			max = area
		}
	}
	return max
}